<!-- 
* 用户页面 
* 2019年5月16日17:06:10
* penglei
* -->
<template>
	<view class="content">
		<view class="_label_top">
			<image class="_btn_top" :src="userAvataUrl"></image>
			<label class="_lab_top">{{userNikeName}}</label>
		</view>
		<view  class="_bg_middle">
			<uni-list>
			    <!-- <uni-list-item title="充值钱包" @click="moment" thumb="../../static/img/money.png"></uni-list-item> -->
				<uni-list-item title="联系客服" opentype="contact" statu="1" thumb="../../static/img/concat.png"></uni-list-item>
				<uni-list-item title="占卜内容回顾" @click="toecs" thumb="../../static/img/word.png"></uni-list-item>
				<uni-list-item title="线下预约" @click="tomake"  thumb="../../static/img/phone.png"></uni-list-item>
				<uni-list-item title="帮助说明" @click="tohelp" thumb="../../static/img/help.png"></uni-list-item>
				<uni-list-item title="关于我们" @click="toabout" thumb="../../static/img/about.png"></uni-list-item>
				<uni-list-item title="H5海报分享" @click="toshare" thumb="../../static/img/user.png"></uni-list-item>
			</uni-list>
		</view>
		<!--< view id="auth" class="btn-row">
			<button type="primary" 
			v-if="canIUse" 
			open-type="getUserInfo"  
			lang="zh_CN"
			v-show="isauth == false"
			@getuserinfo="bindGetUserInfo"
			plain="true" :v-show="isauth==false">授权登录</button>
			<button v-else>请升级微信版本后使用</button>
		</view> -->
	</view>
</template>

<script>
	import uniList from '@/components/uni-list/uni-list.vue'
	import uniListItem from '@/components/uni-list-item/uni-list-item.vue'
	import cmdBottomNav from "@/components/cmd-bottom-nav/cmd-bottom-nav.vue"
	import comm from '../../common/helpers.js'
	import util from '../../static/js/util.js'
    // import {
    //     mapState,
    //     mapMutations
    // } from 'vuex'
    export default {
		components:{cmdBottomNav,uniList,uniListItem},
		data(){
			return{
				userNikeName:'',
				userAvataUrl:'',
				canIUse: uni.canIUse('button.open-type.getUserInfo'),
				isauth:false,
				code:'',
				// 用户openid
				oid:''
			}
		},
		onLoad() {
			comm.showPoster()
			let that = this
			// 验证用户是否已经授权
			uni.getSetting({
				success: (res) => {
					console.log(res)
					if (res.authSetting['scope.userInfo']) {
						uni.getUserInfo({
							success: (res) => {
								that.userNikeName = res.userInfo.nickName
								that.userAvataUrl = res.userInfo.avatarUrl
							}
						})
					}else{
						
					}
				}
			})
			// that.login()
			
			uni.setStorageSync('ue','')
		},
        computed: {
        },
        methods: {
			// queryUsreInfo(){
			// 	let that = this
			// 	 uni.request({
			// 		url: comm.websiteUrl+'?s=v1/getuserid/'+comm.globalData.data.openid, 
			// 		method: 'GET',
			// 		data: {},
			// 		success: res => {
			// 			if(res.code == 404){
			// 				//进行保存用户操作，打开授权按钮
			// 				that.isauth = false
			// 			}
			// 		},
			// 		fail: () => {},
			// 		complete: () => {
			// 		}
			// 	});
			// },
			// bindGetUserInfo(e) {
			// 	//用户按了允许授权按钮
			// 	let that = this;
			// 	//判断数据库是否存在用户，不存在则显示授权按钮，并存入数据库中
			// 	// console.log(e)
			// 	if (e.detail.userInfo) {
			// 		//插入登录的用户的相关信息到数据库
			// 		//获取openID
			// 		that.addUser(e)
			// 		uni.switchTab({
			// 			url: '/pages/divine/main'  
			// 		})
			// 		//授权成功后，跳转进入小程序首页
			// 	} else {
			// 		//用户按了拒绝按钮
			// 		uni.showModal({
			// 			title:'警告',
			// 			content:'您点击了拒绝授权，将无法使用小程序，请授权之后再使用!!!',
			// 			showCancel:false,
			// 			confirmText:'返回授权',
			// 			success:function(res){
			// 				// uni.switchTab({
			// 				// 	url:'/pages/divine/main'
			// 				// })
			// 			}
			// 		})
			// 	}
			// },
			// addUser(e){
			// 	// console.log('-----------------打印openid------------------')
			// 	let that = this
			// 	// console.log(comm.globalData.data.openid)
			// 	uni.request({
			// 		url: comm.websiteUrl + '?s=v1/useradd/',
			// 		method: 'POST',
			// 		data: {
			// 			openid: comm.globalData.data.openid,
			// 			u_name: e.detail.userInfo.nickName,
			// 			u_head: e.detail.userInfo.avatarUrl,
			// 			province:e.detail.userInfo.province,
			// 			city: e.detail.userInfo.city,
			// 			country:e.detail.userInfo.country,
			// 			gender:e.detail.userInfo.gender == 1?"男":"女"
			// 		},
			// 		header: {
			// 			'content-type':'application/x-www-form-urlencoded'
			// 		},
			// 		success: function (res) {
			// 			that.isauth = true
			// 			that.userAvataUrl = e.detail.userInfo.avatarUrl
			// 			that.userNikeName = e.detail.userInfo.nickName
			// 			// uni.switchTab({
			// 			// 	url: '/pages/divine/main'  
			// 			// })
			// 			//从数据库获取用户信息
			// 			// that.queryUsreInfo(e.detail.userInfo.nickName);
			// 			// console.log("插入小程序登录用户信息成功！");
			// 		}
			// 	});
			// },
			// login(){
			// 	let that = this
			// 	//如果未授权，进行授权，并且判断用户是否存在数据库，不存在则提示授权
			// 	uni.login({
			// 		provider: 'weixin',
			// 		success: res => {
			// 			if(res.code){
			// 				that.code = res.code //返回code
			// 				that.getOpenid()
			// 			}else{
			// 				//用户按了拒绝按钮
			// 				uni.showModal({
			// 					title:'警告',
			// 					content:'授权失败，请重新授权!!!',
			// 					success:function(res){
			// 					}
			// 				})
			// 			}
			// 		},
			// 		fail: () => {},
			// 		complete: () => {
			// 			
			// 		}
			// 	});
			// },
			// getOpenid(){
			// 	let that = this
			// 	uni.request({
			// 		url: comm.websiteUrl + '?s=v1/getuseropenid/',
			// 		method: 'POST',
			// 		data: {
			// 			'appid' : comm.appId,
			// 			'appsecret':comm.appSecret,
			// 			'code':that.code
			// 		},
			// 		success: res => {
			// 			uni.setStorageSync('openid',res.data.openid)
			// 			that.oid = res
			// 			comm.globalData = res
			// 		},
			// 		fail: () => {},
			// 		complete: () => {}
			// 	});
			// },
			tohelp(){
				uni.redirectTo({
					url: '/pages/help/help',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			toabout(){
				uni.redirectTo({
					url: '/pages/help/about',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			tomake(){
				uni.redirectTo({
					url: '/pages/make/make',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			moment(){
				uni.redirectTo({
					url: '/pages/user/moment',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			toecs(){
				comm.globalData1 = uni.getStorageSync('globalData')
				uni.redirectTo({
					url: '/pages/user/content?oid='+comm.globalData1.data.openid,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			toshare(){
				util.navTo('/pages/share/share')
			}
		}
    }
</script>

<style lang="scss">
	.content{
		width: 100%;
		height: 100%;
		position: absolute;
		padding: 0upx;
		background-color: white;
		background-image: url('https://zhanbu.nomeis.cn/upload/page_resource/ubg.png');
		background-repeat: no-repeat;
		background-size: 100% 40%;
		
		._label_top{
			width:100%;
			text-align:center;
			margin-top: 45upx;
			
			image{
				width:100upx;
				height:100upx;
			}
			
			._lab_top{
				width:100%;
				display:flex;
				justify-content:center;
				color: white;
				font-size: 11pt;
			}
		}
		
		._bg_middle{
			width:80%;
			margin:auto;
			padding:15upx;
			border-radius:45upx;
			background-color:white;
			box-shadow:2upx 2upx 2upx 2upx gray;
		}
	}
</style>
